package com.day5;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servlet_context_init")
public class ServletContextInit extends HttpServlet {

    @Override
    public void init() throws ServletException {
        //获取servlet context的方式1
        ServletContext servletContext = getServletContext();
        String param = servletContext.getInitParameter("init_param");
        System.out.println(param);
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取servlet context的方式2
        ServletContext servletContext = req.getServletContext();

        ServletContext servletContext1 = req.getSession().getServletContext();
    }
}
